package com.dp.reids;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2018</p>
 * <p>Company: wylCloud.com</p>
 *
 * @author wangyl
 * @version 1.0
 * @date 2022/2/8 11:16
 */
@RestController
public class RedisController {

    /****
     * 远程缓存
     */
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 发布消息
     *
     * @param id
     * @return
     */
    @RequestMapping("/sendMessage/{id}")
    public String sendMessage(@PathVariable String id) {
        for(int i = 1; i <= 5; i++) {
            redisTemplate.convertAndSend("channel:test", String.format("我是消息{%d}号: %tT", i, new Date()));
        }
        return "";
    }
}
